cd "dir:"
clear

/* 
 NOTE: This closely approximates, but does not perfectly match the results
 in Table 6. All conclusions are the same. 
 
 Must specify two values: rhoy and rhox.
 
 Quantities of Interest: 
 ADL: m1xlsig
 ECM: me1lxecm

 ADL Model: y = a + b0x + b1y_(t-1) + b2x_t-1
 ECM Model: dy = a + a1y_t-1 + b0dx + b1x_t-1
*/

 global nobs = 60
 global nmc = 10000
 set seed 5000
 set obs $nobs
 gen id = _n
 tsset id
 
 * Set the values of the parameters
 scalar onetail = 1.645
 scalar ecmsig = -1.645
 scalar ecmMCVm1 = -3.27

 scalar up = 1.96
 scalar lp = -1.96
 scalar alpha = .05
 scalar rhoy = .75
 scalar rhox = .75

 * generating starting value
 gen dv1 = 0
 gen iv1 = 0
 
 * generating error terms
 gen q = .
 gen u = .
 
 tempname sim

 postfile `sim' m1a1 m1sea1 m1ta1 m1b0 m1se0 m1tb0 m1b1 m1se1 m1tb1  m1xlsig ///
 me1a1 me1sea1 me1ta1 me1b0 me1se0 me1tb0 me1b1 me1se1 me1tb1 me1lxecm ///
 using MC_TBL6, replace
 
 quietly {
 forvalues i = 1/$nmc {
 replace q = rnormal()
 replace u = rnormal()
 
 replace dv1 = rhoy*l.dv1 + q in 2/$nobs
 replace iv1 = rhox*l.iv1 + u in 2/$nobs
 
 *******************************************
 
 * Model 1 - ADL * 
 reg dv1 l.dv1 iv1 l.iv1
 
 * Model 1 coefficient values - ADL *
 scalar m1a1 = _b[l.dv1]
 scalar m1b0 = _b[iv1]
 scalar m1b1 = _b[l.iv1]
 * Model 1 standard errors - ADL *
 scalar m1sea1 = _se[l.dv1]
 scalar m1se0 = _se[iv1]
 scalar m1se1 = _se[l.iv1]
 * Model 1 t-statistics - ADL *
 scalar m1ta1 = m1a1/m1sea1
 scalar m1tb0 = m1b0/m1se0
 scalar m1tb1 = m1b1/m1se1
 
 ***** 
 
 * Model 1 - ECM * 
 reg d.dv1 l.dv1 d.iv1 l.iv1
 
 * Model 1 coefficient values - ECM *
 scalar me1a1 = _b[l.dv1]
 scalar me1b0 = _b[d.iv1]
 scalar me1b1 = _b[l.iv1]
 * Model 1 standard errors - ECM * 
 scalar me1sea1 = _se[l.dv1]
 scalar me1se0 = _se[d.iv1]
 scalar me1se1 = _se[l.iv1]
 * Model 1 t-statistics - ECM *
 scalar me1ta1 = me1a1/me1sea1
 scalar me1tb0 = me1b0/me1se0
 scalar me1tb1 = me1b1/me1se1
 
 **************************************************
 
 * Calculating significance totals (Model 1 - ADL)
 scalar m1xlsig = (m1tb1>up | m1tb1<lp)  
 
 * Calculating significance totals - joint hypothesis (Model 1 - ECM) 
 scalar me1lxecm = (me1ta1<ecmsig & (me1tb1>up | me1tb1<lp)) 


 
 ************************************************** 
 
 post `sim' (m1a1) (m1sea1) (m1ta1) (m1b0) (m1se0) (m1tb0) (m1b1) (m1se1) (m1tb1)  (m1xlsig)  ///
 (me1a1) (me1sea1) (me1ta1) (me1b0) (me1se0) (me1tb0) (me1b1) (me1se1) (me1tb1)  (me1lxecm)   ///

 
 }
 }
 postclose `sim'

 use MC_TBL6, clear
 
 sum m1xlsig 
 
 sum me1lxecm 
 
 
 
